/*
 * HelpBrowser.java
 *
 * Created on 28. Februar 2003, 19:27
 */
package de.axelwernicke.mypod.gui;

import java.util.logging.Logger;

import javax.swing.JEditorPane;
import javax.swing.event.HyperlinkEvent;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTMLFrameHyperlinkEvent;


/**
 *
 * @author  axel wernicke
 */
public class HelpBrowser extends javax.swing.JFrame {
    /** jdk1.4 logger */
    private static Logger logger = Logger.getLogger("de.axelwernicke.mypod.gui");

    /** Creates new form HelpBrowser */
    public HelpBrowser(String url) {
        try {
            initComponents();
            jEditorPane.setPage(url);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void initComponents() //GEN-BEGIN:initComponents
     {
        jScrollPane = new javax.swing.JScrollPane();
        jEditorPane = new javax.swing.JEditorPane();

        setTitle(GuiUtils.getStringLocalized("resource/language", "mypodhelpBrowser"));
        addWindowListener(new java.awt.event.WindowAdapter() {
                public void windowClosing(java.awt.event.WindowEvent evt) {
                    exitForm(evt);
                }
            });

        jEditorPane.setEditable(false);
        jEditorPane.setPreferredSize(new java.awt.Dimension(400, 600));
        jEditorPane.addHyperlinkListener(new javax.swing.event.HyperlinkListener() {
                public void hyperlinkUpdate(javax.swing.event.HyperlinkEvent evt) {
                    jEditorPaneHyperlinkUpdate(evt);
                }
            });

        jScrollPane.setViewportView(jEditorPane);

        getContentPane().add(jScrollPane, java.awt.BorderLayout.CENTER);

        pack();
    } //GEN-END:initComponents

    private void jEditorPaneHyperlinkUpdate(javax.swing.event.HyperlinkEvent evt) //GEN-FIRST:event_jEditorPaneHyperlinkUpdate
     { //GEN-HEADEREND:event_jEditorPaneHyperlinkUpdate
        if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
            // log event...
            logger.info("Hyperlink update called for " + evt.getURL());

            JEditorPane pane = (JEditorPane) evt.getSource();
            if (evt instanceof HTMLFrameHyperlinkEvent) {
                HTMLFrameHyperlinkEvent hevt = (HTMLFrameHyperlinkEvent) evt;
                HTMLDocument doc = (HTMLDocument) pane.getDocument();
                doc.processHTMLFrameHyperlinkEvent(hevt);
            } else {
                try {
                    pane.setPage(evt.getURL());
                } catch (Throwable t) {
                    t.printStackTrace();
                }
            }
        }
    } //GEN-LAST:event_jEditorPaneHyperlinkUpdate

    /** Exit the Application */
    private void exitForm(java.awt.event.WindowEvent evt) { //GEN-FIRST:event_exitForm
    } //GEN-LAST:event_exitForm

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JEditorPane jEditorPane;
    private javax.swing.JScrollPane jScrollPane;

    // End of variables declaration//GEN-END:variables
}
